package com.kyivmohyla.kma2.dao.mapper;

import com.kyivmohyla.kma2.model.Order;
import org.springframework.jdbc.core.ResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;

class OrderResultSetExtractor implements ResultSetExtractor<Order> {

    @Override
    public Order extractData(ResultSet resultSet) throws SQLException {
        Order order = new Order();
        try {
            order.setOrderId(resultSet.getInt("order_id"));
            order.setCreateDate(resultSet.getTimestamp("create_date"));
            order.setStartDate(resultSet.getTimestamp("start_date"));
            order.setEndDate(resultSet.getTimestamp("end_date"));
            order.setDesStartDate(resultSet.getTimestamp("des_start_date"));
            order.setDesEndDate(resultSet.getTimestamp("des_end_date"));
            order.setCommentary(resultSet.getString("commentary"));
            order.setStateId(resultSet.getInt("state_id"));
            order.setCustomerId(resultSet.getInt("customer_id"));
            order.setEngineerId(resultSet.getInt("engineer_id"));
            order.setStateName(resultSet.getString("state_name"));
            order.setCustomerName(resultSet.getString("customer_name"));
            order.setCustomerAddress(resultSet.getString("customer_address"));
            try {
                order.setEngineerName(resultSet.getString("engineer_name"));
            } catch (SQLException e) {
                order.setEngineerName("");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return order;
    }
}